package com.millstein.tsinglog.model.vo.result;

import com.millstein.tsinglog.commons.enums.ResultCode;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用结果返回类
 */
@Data
@NoArgsConstructor
public class CommonResult {
    private int code;
    private String message;
    private Object data;

    public CommonResult(ResultCode code) {
        this(code, null);
    }

    public CommonResult(ResultCode code, Object data) {
        this.code = code.getCode();
        this.message = code.getMessage();
        this.data = data;
    }

    public static CommonResult success() {
        CommonResult commonResult = new CommonResult(ResultCode.SUCCESS);
        return commonResult;
    }

    public static CommonResult success(Object data) {
        CommonResult commonResult = new CommonResult(ResultCode.SUCCESS);
        commonResult.setData(data);
        return commonResult;
    }

    public static CommonResult failure(ResultCode code) {
        CommonResult commonResult = new CommonResult(code);
        return commonResult;
    }

    public static CommonResult failure(ResultCode code, Object data) {
        CommonResult commonResult = new CommonResult(code);
        commonResult.setData(data);
        return commonResult;
    }
}